/*
 * @Descripttion:
 * @version:
 * @Author: 闫旭
 * @Date: 2020-12-31 14:25:41
 * @LastEditors: sueRimn
 * @LastEditTime: 2021-10-22 09:09:11
 */

function handleLocalStorage(method, key, value) {
  switch (method) {
    case "get": {
      let temp = window.localStorage.getItem(key);
      if (temp) {
        return temp;
      } else {
        return false;
      }
    }
    case "set": {
      window.localStorage.setItem(key, value);
      break;
    }
    case "remove": {
      window.localStorage.removeItem(key);
      break;
    }
    default: {
      return false;
    }
  }
}

//  轮播图初始化函数
function initArrSwiper(index) {
  if (index == 0) {
    index = "";
  }
  new Swiper(".swiper-container-intro" + index, {
    autoplay: 5000, //可选选项，自动滑动
    loop: true, //可选选项，开启循环
    // 如果需要前进后退按钮
    navigation: {
      nextEl: ".arrow-right",
      prevEl: ".arrow-left",
    },
    pagination: ".pagination-intro" + index,
    paginationClickable: true,
  });
}

$(function () {
  // 循环初始化轮播图
  for (var index = 0; index <= 3; index++) {
    initArrSwiper(index);
  }

  //文字 两行剪切
  $(".content > h4 > a").each(function () {
    var maxwidth = 160;
    if ($(this).text().length > maxwidth) {
      $(this).text($(this).text().substring(0, maxwidth));
      $(this).html($(this).html() + "…");
    }
  });

  // tab切换
  var $tab = $(".swiper ul li");
  $tab.on("mouseenter", function () {
    var index = $(this).index();
    $(this)
      .find("a")
      .addClass("cur")
      .parent()
      .siblings()
      .find("a")
      .removeClass("cur");
    $(this)
      .find("div")
      .addClass("dis")
      .parent()
      .siblings()
      .find("div")
      .removeClass("dis");
    $(this)
      .parents(".swiper")
      .siblings(".swiper_content")
      .find(".right_news")
      .addClass("undis")
      .eq(index)
      .removeClass("undis");
    return false;
  });

  // 产业布局
  var introduction = true;
  var industry = $(".industry .energy ul li");
  industry.on("mouseenter", function () {
    var index = $(this).index();
    if (introduction) {
      $(".introduction").hide();
      introduction = false;
    }

    $(this).find("div").css("font-size", "18px");
    $(this).css({
      background: "#00CE91",
      transform: "scale(1.1)",
    });
    $(this).siblings().find("div").css("font-size", "16px");
    $(this).siblings().css({
      background: "rgba(0, 108, 255, 0.45)",
      transform: "scale(1)",
    });
    $(this).find("img").addClass("route360");
    $(this).siblings().find("img").removeClass("route360");

    $(".energy_content")
      .not(".introduction")
      .addClass("undis")
      .eq(index)
      .removeClass("undis");
  });

  // 图片列表切换
  var $tab1 = $(".swiper_list ul li");
  $tab1.on("mouseenter", function () {
    var index = $(this).index();
    $(this)
      .parents(".swiper")
      .siblings(".picture_list")
      .addClass("undis")
      .eq(index)
      .removeClass("undis");
    return false;
  });

  $(".left_big1").hover(
    function () {
      $(this).find("span").addClass("col_common");
    },
    function () {
      $(this).find("span").removeClass("col_common");
    }
  );
  $.ajax({
    url: "http://nengyuan.chuangqi.34hy.cn/stock",
    type: "GET",
    success: function (result) {
      var res = JSON.parse(result);
      console.log(res, "rrr");
      stockList = res.data;
      renderHtml();
    },
  });

  function renderHtml() {
    if (!stockList || stockList.length === 0) {
      stockList = [];
      return;
    }

    var htmlStr = template("getStock", { message: stockList });
    $("#stock_list").html(htmlStr);
  }

  // 首页访问量
  function addPv() {
    $.ajax({
      url: "http://app.iqilu.com/pv/" + orgid + "/views",
      type: "GET",
      success: function (res) {
        var str = "当前访问量：" + res.data + "次";
        $(".footer_bottom .footer_bottom_inner >:nth-child(2)").text(str);
      },
    });
  }
  try {
    addPv();
  } catch (error) {
    console.log("2");
  }

  var ad1 = new AdMove("pc1", "close_btn");
  ad1.Run();

  /**
   * @description: 2021/10/22
   * @param {*}   判断飘窗是否有
   * @return {*}
   */
  $("#pc1").find("span").text() == "1" ? $("#pc1").show() : $("#pc1").hide();

  function closeCanvas(params) {
    $(".first_div").fadeOut();
    $("#canvas").fadeOut();
  }

  // 弹窗取消
  $(".first_div .close_btn").click(function () {
    closeCanvas();
  });

  // var firsrResult = handleLocalStorage("get", "_first");
  // // if (!firsrResult) {
  // //   handleLocalStorage("set", "_first", true);
  // // } else {
  // //   $("#canvas").hide();
  // //   $(".first_div").hide();
  // // }
  var canvas = setTimeout(function () {
    closeCanvas();
    canvas = null;
  }, 5000);
});
